/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.dialog;


import gui.Window;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import moteur.Plateau;

/**
 *
 * @author Jean
 */
public class DialogNewGame extends JDialog implements ActionListener
{

    public ButtonGroup versus;
    public ButtonGroup couleurDeb;
    public JComboBox levelIA;
    private final String[] items =
    {
        "FACILE (3)", "MOYEN (6)", "HARD (9)", "PGM (12)"
    };
    /*Mise en attribut de ces 2 boutons pour y avoir acces dans le actionPerformed */
    JRadioButton C2;
    JRadioButton b;
    Window frame;

    public DialogNewGame(JFrame frame)
    {
        super(frame);
        this.frame = (Window)(frame); 
        initComponent();
        setResizable(false);
    }

    private void initComponent()
    {
        levelIA = new JComboBox(items);
        JPanel nord = new JPanel(new GridLayout(2, 2));
        //nord.setLayout(new BoxLayout(nord, BoxLayout.Y_AXIS));

        versus = new ButtonGroup();
        JRadioButton J2 = new JRadioButton("Human Vs Human");
        J2.addMouseListener(new MouseListener()
        {

            public void mouseClicked(MouseEvent e)
            {
                levelIA.setEnabled(false);
                //levelIA.setVisible(false);
            }

            public void mousePressed(MouseEvent e)
            {
            }

            public void mouseReleased(MouseEvent e)
            {
            }

            public void mouseEntered(MouseEvent e)
            {
            }

            public void mouseExited(MouseEvent e)
            {
            }
        });

        C2 = new JRadioButton("Human Vs Computer", true);
        C2.addMouseListener(new MouseListener()
        {

            public void mouseClicked(MouseEvent e)
            {
                levelIA.setEnabled(true);
                levelIA.setVisible(true);
            }

            public void mousePressed(MouseEvent e)
            {
            }

            public void mouseReleased(MouseEvent e)
            {
            }

            public void mouseEntered(MouseEvent e)
            {
            }

            public void mouseExited(MouseEvent e)
            {
            }
        });
        versus.add(C2);
        versus.add(J2);
        nord.add(C2);
        nord.add(levelIA);
        nord.add(J2);

        JPanel sud = new JPanel(new FlowLayout(FlowLayout.CENTER));
        couleurDeb = new ButtonGroup();
        JRadioButton n = new JRadioButton("Noir", true);
        b = new JRadioButton("Blanc");
        couleurDeb.add(n);
        couleurDeb.add(b);

        JButton ok = new JButton("GO");
        ok.addActionListener(this);
        this.add(ok);

        sud.add(n);
        sud.add(b);

        this.add(nord, BorderLayout.WEST);
        this.add(sud, BorderLayout.SOUTH);
        pack();

    }

    public void actionPerformed(ActionEvent e)
    {
        char c = ' '; // pour stocker contre qui il veut jouer (humain ou ordi)
        int difficulte = 0; // stocker la difficulté
        char coul = 'n'; // stocker avec quelle couleur il veut jouer
        if (C2.isSelected())
        {
            c = 'c';
            difficulte = levelIA.getSelectedIndex();
        }
        else
        {
            c = 'h';
        }
        if (b.isSelected())
        {
            coul = 'b';
        }
        this.frame.peauNeuve();
        Plateau.getInstance().paramNewPlat( c, difficulte, coul);
        dispose(); // fermeture de la boite "nouvelle partie"
    }
}
